﻿function get_Admins_Html(){
  var htmlstr='<table id="Grid_Admins" style="width:auto;height:auto"></table><div id="addAdminsdiv" style="display:none"></div><div id="edtAdminsdiv" style="display:none"></div>';
  return htmlstr;
}
function getadd_Admins_Html(){
  var htmlstr='<div id="AddDlg_Admins" title="添加记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="380" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="100"> 帐号 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Account" id="add_Account" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 密码 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Pass" id="add_Pass" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 权限分类 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_AdminType" id="add_AdminType" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 昵称 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_NickName" id="add_NickName" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 真名 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_RealName" id="add_RealName" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 年龄 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="add_Aeg" id="add_Aeg" /></td></tr>';
  htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="addbt_Admins" href="javascript:void(0)" onclick="Add_Admins()"> 添 加 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function getedt_Admins_Html(){
  var htmlstr='<div id="EditDlg_Admins" title="修改记录" icon="icon-window" style="padding:5px;background:#fafafa">';
  htmlstr=htmlstr+'<div class="easyui-layout" fit="true">';
  htmlstr=htmlstr+'<div region="center" border="false" style="padding:10px;background:#fff;border:1px solid #ccc;">';
  htmlstr=htmlstr+'<table width="380" border="0" class="dtable" align="center" cellpadding="4" cellspacing="0">';
  htmlstr=htmlstr+'<tr><td width="100"> 密码 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="edt_Pass" id="edt_Pass" /></td></tr>';
  htmlstr=htmlstr+'<tr><td> 确认 </td>';
  htmlstr=htmlstr+'<td><input type="text" name="edt_Pass2" id="edt_Pass2" /></td></tr>';
  htmlstr=htmlstr+'</table></div><div region="south" border="false" style="text-align:right;padding-top:4px;height:30px;line-height:30px;">';
  htmlstr=htmlstr+'<a icon="icon-ok" id="edtbt_Admins" href="javascript:void(0)" onclick="Edit_Admins()"> 修 改 </a>';
  htmlstr=htmlstr+'</div></div>';
  return htmlstr;
}
function Add_Admins_Tab(tabname){
  if(!$('#ttab').tabs('exists',tabname)){
	$('#ttab').tabs('add',{
		title:tabname,
		cache:false,
		closable:true,
		content:get_Admins_Html()
	  });
	var gridht = $('body').layout('panel','center').panel('options').height - 58;
	$('#Grid_Admins').datagrid({
	  border:false,
	  nowrap: false,
	  striped: true,
	  collapsible:true,
	  url:'/Data/Admins.ashx',
	  method:'get',
	  height:gridht,
	  queryParams:{type:"0"},
	  fitColumns:true,
	  loadMsg:'正在读取数据,请稍候...',
	  singleSelect:true,
	  columns:[[
		{field:'AdminId',checkbox:true},
		{field:'Account',title:'帐号',width:80},
		{field:'AdminType',title:'管理级别',width:80},
		{field:'NickName',title:'昵称',width:80},
		{field:'RealName',title:'真名',width:80},
		{field:'Aeg',title:'年龄',width:80},
		{field:'IsClose',title:'关闭',width:80,formatter:BoolFormat},
		{field:'LastIP',title:'最后IP',width:80},
		{field:'LastTime',title:'最后时间',width:180},
		{field:'bitlock',title:'锁定',width:80,formatter:BoolFormat}]],
	  pagination:true,
	  rownumbers:true,
	  toolbar:[{
		id:'btn_Admins_add',
		text:'添加管理员',
		iconCls:'icon-add',
		handler:function(){
		  ShowAdminsAddFrom();}
		},'-',{
		id:'btn_Admins_close',
		text:'关闭访问',
		iconCls:'icon-ordercancel',
		handler:function(){
		  GetOne_Admins();}
		},'-',{
		id:'btn_Admins_key',
		text:'解锁帐号',
		iconCls:'icon-key',
		handler:function(){
		  GetOne_Admins();}
		},'-',{
		id:'btn_Admins_edit',
		text:'修改密码',
		iconCls:'icon-edit',
		handler:function(){
		  GetOne_Admins();}
		},'-',{
		id:'btn_Admins_del',
		text:'删除帐号',
		iconCls:'icon-remove',
		handler:function(){
		  Del_Admins();}
	  }],
	  onLoadError:function(er){
		  $.messager.alert('错误','可能无查看权限,无法加载数据!','error');
	  }
	});
  }else{
	$('#ttab').tabs('select',tabname);
  }
}
function ShowAdminsAddFrom(){
  $('#addAdminsdiv').html(getadd_Admins_Html());
  $.parser.parse($('#addAdminsdiv'));
  $('#AddDlg_Admins').window({
	  title: '添加管理员',
	  width: 450,
	  modal: true,
	  shadow: true,
	  closed: true,
	  height: 280
  });
  $('#addbt_Admins').linkbutton({iconCls:"icon-ok"});
  $('#AddDlg_Admins').window('open');
}
function ShowAdminsEdtFrom(){
  $('#edtAdminsdiv').html(getedt_Admins_Html());
  $.parser.parse($('#edtAdminsdiv'));
}
function Add_Admins(){
  $.get("/Data/Admins.ashx",{type:2,Account:$('#add_Account').val(),Pass:$('#add_Pass').val(),ContentInfo:$('#add_ContentInfo').val(),AdminType:$('#add_AdminType').val(),AdminPower:$('#add_AdminPower').val(),NickName:$('#add_NickName').val(),RealName:$('#add_RealName').val(),FaceId:$('#add_FaceId').val(),Aeg:$('#add_Aeg').val(),IsClose:$('#add_IsClose').val(),SessionKey:$('#add_SessionKey').val(),LastIP:$('#add_LastIP').val(),LastTime:$('#add_LastTime').val(),dteErrs:$('#add_dteErrs').val(),intErr:$('#add_intErr').val(),bitlock:$('#add_bitlock').val()},
  function(data){
    $('#AddDlg_Admins').window('close');
	$('#Grid_Admins').datagrid("reload");
  });
}
function GetOne_Admins(){
  var getid=0;
  var selected = $('#Grid_Admins').datagrid('getSelected');
  if (selected){
    getid=selected.AdminId;
	$.getJSON("/Data/Admins.ashx",{type:1,id:getid},
	function(data){
			ShowAdminsEdtFrom();
			$('#EditDlg_Admins').window({
				title: 'Edit Admins',
				width: 450,
				modal: true,
				shadow: true,
				closed: true,
				height: 160
				});
			$('#EditDlg_Admins').window('open');
			$('#edtbt_Admins').linkbutton({iconCls:"icon-ok"});
						$('#edt_AdminId').val(data.model.AdminId);
						$('#edt_Account').val(data.model.Account);
						$('#edt_Pass').val(data.model.Pass);
						$('#edt_ContentInfo').val(data.model.ContentInfo);
						$('#edt_AdminType').val(data.model.AdminType);
						$('#edt_AdminPower').val(data.model.AdminPower);
						$('#edt_NickName').val(data.model.NickName);
						$('#edt_RealName').val(data.model.RealName);
						$('#edt_FaceId').val(data.model.FaceId);
						$('#edt_Aeg').val(data.model.Aeg);
						$('#edt_IsClose').val(data.model.IsClose);
						$('#edt_SessionKey').val(data.model.SessionKey);
						$('#edt_LastIP').val(data.model.LastIP);
						$('#edt_LastTime').val(data.model.LastTime);
						$('#edt_dteErrs').val(data.model.dteErrs);
						$('#edt_intErr').val(data.model.intErr);
						$('#edt_bitlock').val(data.model.bitlock);
			
      });
	}else{
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
	}
}
function Chang_My_Pass(){
  ShowAdminsEdtFrom();
  $('#EditDlg_Admins').window({
	  title: '修改本帐号密码',
	  width: 450,
	  modal: true,
	  shadow: true,
	  closed: true,
	  height: 160
	  });
  $('#edtbt_Admins').linkbutton({iconCls:"icon-ok"});
  $('#EditDlg_Admins').window('open');	
}
function Edit_Admins(){
  $.get("/Data/Admins.ashx",{type:4,AdminId:$('#edt_AdminId').val(),Account:$('#edt_Account').val(),Pass:$('#edt_Pass').val(),ContentInfo:$('#edt_ContentInfo').val(),AdminType:$('#edt_AdminType').val(),AdminPower:$('#edt_AdminPower').val(),NickName:$('#edt_NickName').val(),RealName:$('#edt_RealName').val(),FaceId:$('#edt_FaceId').val(),Aeg:$('#edt_Aeg').val(),IsClose:$('#edt_IsClose').val(),SessionKey:$('#edt_SessionKey').val(),LastIP:$('#edt_LastIP').val(),LastTime:$('#edt_LastTime').val(),dteErrs:$('#edt_dteErrs').val(),intErr:$('#edt_intErr').val(),bitlock:$('#edt_bitlock').val()},
  function(data){
    $('#EditDlg_Admins').window('close');
	$('#Grid_Admins').datagrid("reload");
  }); 
}
function Del_Admins(){
  var getid=0;
  var selected = $('#Grid_Admins').datagrid('getSelected');
  if(!selected){
	        $.messager.show({
				title:'提示',
				msg:'没有选择任何记录.',
				timeout:3000,
				showType:'slide'
			});
			return;
  }
  
  getid=selected.AdminId;
  $.messager.confirm('确认删除', '请确认是否进行此操作?', function(r){
	  if(r){
			$.get("/Data/Admins.ashx",{type:3,id:getid},
			function(data){
				$.messager.show({
					title:'提示',
					msg:'已删除数据.',
					timeout:3000,
					showType:'slide'
				});
				$('#Grid_Admins').datagrid("reload");
			}); 
		  }
  }); 
} 
  